package pager

type Result[T any] struct {
	Total     int `json:"total"`
	Pages     int `json:"pages"`
	Items     []T `json:"items"`
	PageIndex int `json:"page_index"`
	PageSize  int `json:"page_size"`
}

func EmptyResult[T any](req Req) Result[T] {
	return Result[T]{
		Total:     0,
		Items:     nil,
		PageIndex: req.PageIndex,
		PageSize:  req.GetLimit(),
		Pages:     0,
	}
}

func NewResult[T any](data []T, total int, req Req) Result[T] {
	return Result[T]{
		Total:     total,
		Items:     data,
		PageIndex: req.PageIndex,
		PageSize:  req.GetLimit(),
		Pages:     total / req.GetLimit(),
	}
}
